﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace LimpaGaragem.DAO.Product
{
    public class ProductFlaggedType
    {
        /// <summary>
        /// Return list of product flagged type
        /// </summary>
        /// <returns></returns>
        public List<LimpaGaragem.Model.Product.ProductFlaggedType> GetListOfProductFlaggedType()
        {
            try
            {
                Framework.DataAccess objDataAccess = new Framework.DataAccess();
                DataTable objDataTable = objDataAccess.ReturnDataTable(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, Framework.DataAccess.QueryType.Procedure, "PR017_ListProductFlaggedTypes", 0);

                List<LimpaGaragem.Model.Product.ProductFlaggedType> objListOfProductFlaggedType = new List<LimpaGaragem.Model.Product.ProductFlaggedType>();
                foreach (DataRow objDataRow in objDataTable.Rows)
                {
                    LimpaGaragem.Model.Product.ProductFlaggedType objProductFlaggedType = new LimpaGaragem.Model.Product.ProductFlaggedType();
                    objProductFlaggedType.ID = Convert.ToInt32(objDataRow["ID_PRODUCT_FLAGGED_TYPE"]);
                    objProductFlaggedType.Name = objDataRow["NM_PRODUCT_FLAGGED_TYPE"].ToString();
                    objListOfProductFlaggedType.Add(objProductFlaggedType);
                }
                return objListOfProductFlaggedType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Return data of product flagged type
        /// </summary>
        /// <returns></returns>
        public LimpaGaragem.Model.Product.ProductFlaggedType GetProductFlaggedType(int IDProductFlaggedType)
        {
            try
            {
                Framework.DataAccess objDataAccess = new Framework.DataAccess();

                //PARAMETERS
                List<SqlParameter> objListOfParameters = new List<SqlParameter>();
                objListOfParameters.Add(new SqlParameter("@ID_PRODUCT_FLAGGED_TYPE", IDProductFlaggedType));

                //RETURN DATA
                DataTable objDataTable = objDataAccess.ReturnDataTable(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, Framework.DataAccess.QueryType.Procedure, "PR017_SelectProductFlaggedType", 0, objListOfParameters);

                LimpaGaragem.Model.Product.ProductFlaggedType objProductFlaggedType = null;
                if (objDataTable.Rows.Count > 0)
                {
                    objProductFlaggedType = new LimpaGaragem.Model.Product.ProductFlaggedType();
                    objProductFlaggedType.ID = IDProductFlaggedType;
                    objProductFlaggedType.Name = objDataTable.Rows[0]["NM_PRODUCT_FLAGGED_TYPE"].ToString();
                }
                return objProductFlaggedType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
